package com.castle.fortress.admin.schedule.model.entity;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.castle.fortress.admin.schedule.model.vo.StudyScheduleVO;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 
 * @author fkrbl
 * @TableName study_schedule
 */
@TableName(value ="study_schedule")
@Data
public class StudySchedule implements Serializable {
    /**
     * 主键
     */
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 标题
     */
    private String title;

    /**
     * 任务时间
     */
    private Date taskTime;

    /**
     * 需要时间，单位为分钟
     */
    private Integer estimatedTime;

    /**
     * 状态，0为完成，1完成
     */
    private Integer status;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    public StudyScheduleVO toVO() {
        StudyScheduleVO vo = new StudyScheduleVO();
        vo.setId(id);
        vo.setUserId(userId);
        vo.setTitle(title);
        vo.setTaskTime(taskTime);

        // int to string
        if(estimatedTime != null) {
            vo.setEstimatedTime(estimatedTime+"分钟");
        }

        // calc difficulty
        String difficulty = "简单";
        if(estimatedTime != null) {
            if (estimatedTime > 45) {
                difficulty = "困难";
            } else if (estimatedTime > 20) {
                difficulty = "中等";
            }
        }
        vo.setDifficulty(difficulty);

        vo.setStatus(status);
        return vo;
    }
    public static List<StudySchedule> getDefaultScheduleList() {
        StudySchedule s1 = new StudySchedule();
        s1.setTitle("背诵单词");
        s1.setEstimatedTime(20);
        StudySchedule s2 = new StudySchedule();
        s2.setTitle("复习课程");
        s2.setEstimatedTime(40);
        StudySchedule s3 = new StudySchedule();
        s3.setTitle("预习课程");
        s3.setEstimatedTime(15);
        return Arrays.asList(s1, s2, s3);
    }
}